package com.winsomely.leecode;

/**
 * 字符串相加
 * 
 * @author liujiawei
 *
 */
public class AddStrings {

	public String addStrings(String num1, String num2) {
		int n1 = num1.length() - 1;
		int n2 = num2.length() - 1;
		String s = "";
		int jw = 0;
		while (n1 >= 0 || n2 >= 0) {
			int n1n = 0, n2n = 0;
			if (n1 >= 0) {
				n1n = Integer.valueOf(String.valueOf(num1.charAt(n1--)));
			}
			if (n2 >= 0) {
				n2n = Integer.valueOf(String.valueOf(num2.charAt(n2--)));
			}
			int wh = n1n + n2n + jw;
			int bw = wh >= 10 ? wh - 10 : wh;
			jw = wh >= 10 ? 1 : 0;
			s = bw + s;
		}
		return jw != 0 ? jw + s : s;
	}

	public static void main(String[] args) {
		AddStrings t = new AddStrings();
		String num1 = "99999999999999999999";
		String num2 = "0";
		System.out.println(t.addStrings(num1, num2));
	}

}
